<?php
class channelController extends RPHP_Controller
{

    //权限前缀
    protected $_pvprefix = "channel";
    //规格重组
    public function ceshi()
    {
        $model = $this->model;
        $model->getGoodsStockInfoV2(1257);
    }
    //商品设置规格属性
    public function goods_spec_set()
    {
        
        $priv = array($this->_pvprefix . "_gsc");
        
        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $goods_id = intval($_GET['goods_id']);
            $cate_id = intval($_GET['cate_id']);
            if($goods_id && $cate_id){
                
               
                $this->view->auth = $auth;
                $this->view->goods_id =$goods_id;
                $this->view->data = $model->getGoodsSpecs(0, false,$cate_id);
                //PRINT_R($this->view->data);DIE;
                $this->view->goods_spec = $model->getGoodsStockList($goods_id);
                $this->display();
             }
        
        }
    }

    //设置商品规格图片页面
    public function goods_spec_pic()
    {
        $priv = array($this->_pvprefix . "_gsc");
        
        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $cate_id = intval($_GET['cate_id']);
            $goods_id= intval($_GET['goods_id']);
            if($cate_id && $goods_id){
        
                $this->view->auth = $auth;
                //$data=$model-> getGoodsSpecPic($goods_id);
             
                $this->view->data = $model->getGoodsSpecs(0, false,$cate_id,$goods_id);
                $this->display();
            }
        
        }
    }
    
    

    //规格
    public function spec()
    {
    
        $priv = array($this->_pvprefix . "_sc");
    
        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        // var_dump($auth);exit;
        if ($auth) {
            $this->view->auth = $auth;
    // var_dump($model->checkPriv($this->_pvprefix . "_csad", false));exit;
            $cate_id = intval($_GET['cate_id']);           //获取类型数据
            $this->view->data = $model->getSpec(0, false,$cate_id);
            // print_r($this->view->data );die;
            //获取新增权限
            $this->view->pvadd = $model->checkPriv($this->_pvprefix . "_scad", false);
            //获取编辑权限
            $this->view->pvedit = $model->checkPriv($this->_pvprefix . "_sced", false);
    
            $this->display();
    
        }
    
    }
    
    //新增规格
    public function specadd()
    {
    
        $priv = array($this->_pvprefix . "_scad");
    
        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            
            $cate_id = intval($_GET['cate_id']);
            $this->view->auth = $auth;
            //获取分类数据
            $this->view->data = $model->getSpec(0,false,$cate_id);
            $this->view->cate_id = $cate_id;
            $this->display();
    
        }
    
    }
    
    //编辑规格
    public function specedit()
    {
      
        $priv = array($this->_pvprefix . "_scad");
    
        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;
            $caid = intval($_GET['caid']);
            $cate_id = intval($_GET['cate_id']);
            $cate = $model->getSpec($caid,false,$cate_id);
             
           
    
            if ($cate) {
                $this->view->cate                            = $cate;
                $this->view->stat[$this->view->cate['stat']] = ' checked';
    
                //获取类型数据
                $this->view->data = $model->getSpec(0,false,$cate_id);
                $this->display();
            }
    
        }
    
    }
    //规格排序
    public function specsort()
    {
    
        $priv = array($this->_pvprefix . "_sced");
    
        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) { 
            $cate_id = intval($_GET['cate_id']);
            $this->view->auth = $auth;
            $this->view->data = $model->getSpec(intval($_GET['caid']), true,$cate_id);
            $this->display();
    
        }
    
    }
    //规格操作
    public function specdo()
    {
    
        $priv = array($this->_pvprefix . "_sc");
    
        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;
            $this->view->code = 900;
    
            if ($_POST['act'] == "add" && $model->checkPriv($this->_pvprefix . "_scad", false, false)) {
    
                $this->view->success = "新增规格成功";
                $this->view->link    = array(
                    array('name' => '继续新增商品规格', 'url' => '/channel/specadd?cate_id='.$_POST['cate_id']),
                    array('name' => '返回商品规格列表', 'url' => '/channel/spec?cate_id='.$_POST['cate_id']),
                );
                $this->view->code = $model->saveSpec($_POST,0,$_POST['cate_id']);
    
            } elseif ($_POST['act'] == "edit" ) {
    
                $this->view->success = "编辑规格成功";
                $this->view->link    = array(
                    array('name' => '返回规格列表', 'url' => '/channel/spec?cate_id='.$_POST['cate_id']),
                );
                $this->view->code = $model->saveSpec($_POST,$_POST['caid'],$_POST['cate_id']);
    
            } elseif ($_POST['act'] == "sort") {
                $this->view->success = "保存规格排序成功";
                $this->view->link    = array(
                    array('name' => '返回规格列表', 'url' => '/channel/spec?cate_id='.$_POST['cate_id']),
                );
               
                $this->view->code = $model->saveSpecSort($_POST);
    
            } elseif ($_POST['act'] == "sevaGoodSpecsPic") {
                $this->view->success = "保存规格图片成功";
                $this->view->link    = array(
                    array('name' => '返回规格图片设置', 'url' => 'goods_spec_pic?cate_id='.$_POST['cate_id'].'&goods_id='.$_POST['goods_id']),
                    
                );
                $this->view->code = $model->saveSpecPic($_POST,$_FILES['pic'],$_POST['goods_id']);
    
            }
    
            $this->displaydo();
    
        }
    
    }


    //关键词表
    public function keywords_list()
    {
        $priv = array($this->_pvprefix . "_kw");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {

            if ($_GET['keyword'] != "") {
                $keyword = addslashes(trim($_GET['keyword']));
                if ($keyword != '') {
                    $para['keyword'] = $keyword;
                }

            }

            if ($_GET['start_time'] != "") {
                $start_time = strtotime($_GET['start_time']);
                if ($start_time > 0) {
                    $para['start_time'] = $start_time;
                }
            }
            if ($_GET['end_time'] != "") {
                $end_time = strtotime($_GET['end_time']);
                if ($end_time > 0) {
                    $para['end_time'] = $end_time;
                }

            }

            if (intval($_GET['page']) > 0) {
                $page = intval($_GET['page']);
            } else {
                $page = 1;
            }


            $data = $model->getKeywordsList($para, $page);

            //获取页码
            if ($data['maxpage'] > 1) {
                $data['spage'] = $model->fun->spage($data['page'], $data['maxpage']);
            }

            $this->view->data = $data;
            $this->view->auth = $auth;
            $this->display();
        }
    }

    //快递类型
    public function express_type()
    {
        $priv = array($this->_pvprefix . "_ext");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;
            $this->display();
        }
    }
//关联管理
    public function relevancelist()
    {
        $priv = array($this->_pvprefix . "_rele");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {

            $para = array();
            if (intval($_GET['page']) > 0) {
                $page = intval($_GET['page']);
            } else {
                $page = 1;
            }

            if (!empty($_GET['keyword'])) {
                $para['keyword'] = addslashes(stripslashes(trim($_GET['keyword'])));
            }

            if ($_GET['status'] != "") {
                $para['status'] = intval($_GET['status']);
            }
            $this->view->auth = $auth;
            $this->view->data = $model->getRelevanceList($para, $page);
            //获取页码
            if ($this->view->data['maxpage'] > 1) {
                $this->view->data['spage'] = $model->fun->spage($this->view->data['page'], $this->view->data['maxpage']);
            }

            $this->display();
        }

    }

    public function relevancel_add()
    {
        $priv = array($this->_pvprefix . "_rele");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;
            if ($_POST['act'] == "rele_add") {
                $this->view->code    = 900;
                $this->view->success = "新增关联成功";
                $this->view->link    = array(
                    array('name' => '继续新增关联', 'url' => '/channel/relevancel_add'),
                    array('name' => '返回关联列表', 'url' => '/channel/relevancelist'),
                );
                $this->view->code = $model->saveRelevance($_POST);
                $this->displaydo();
            } else {
                $this->display();
            }

        }

    }

    public function relevancel_edit()
    {
        $priv = array($this->_pvprefix . "_rele");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;
            if ($_POST['act'] == "rele_edit") {
                $this->view->code    = 900;
                $this->view->success = "编辑关联成功";
                $this->view->link    = array(
                    array('name' => '继续编辑关联', 'url' => '/channel/relevancel_edit?id=' . $_POST['id']),
                    array('name' => '返回关联列表', 'url' => '/channel/relevancelist'),
                );
                $this->view->code = $model->saveRelevance($_POST, $_POST['id']);
                $this->displaydo();
            } else {
                $id               = intval($_GET['id']);
                $data             = $model->getRelevancel($id);
                $this->view->data = $data;
                $this->display();
            }

        }

    }

    public function rele_del()
    {
        $priv  = array($this->_pvprefix . "_rele");
        $arr   = array();
        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $id       = intval($_GET['id']);
            $goods_id = intval($_GET['goods_id']);

            $data = $model->delRele($id, $goods_id);
            echo json_encode($data);
        }

    }

/*----商品--------------------*/

    //渠道商品
    public function channelgoods()
    {

        $priv = array($this->_pvprefix . "_cl");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;

            if ($_GET['stat'] != "") {
                $stat = addslashes(trim($_GET['stat']));
            }

            if ($_GET['keyword'] != "") {
                $keyword = addslashes(trim($_GET['keyword']));
                if ($keyword != '') {
                    $para['keyword'] = $keyword;
                }

            }
            if ($_GET['caid'] != "") {
                $caid = intval($_GET['caid']);
                if ($caid > 0) {
                    $para['caid'] = $caid;
                }

            }
            if ($_GET['supplier_id'] != "") {
                $supplier_id = intval($_GET['supplier_id']);
                if ($supplier_id > 0) {
                    $para['supplier_id'] = $supplier_id;
                }

            }
            if ($_GET['goods_type'] != "") {
                $goods_type = intval($_GET['goods_type']);
                if ($goods_type > 0) {
                    $para['goods_type'] = $goods_type;
                }

            }
            if (isset($_GET['is_on_sale']) && $_GET['is_on_sale'] != "") {
                $is_on_sale = intval($_GET['is_on_sale']);
                if ($is_on_sale >= 0) {
                    $para['is_on_sale'] = $is_on_sale;
                }
            }

            if (isset($_GET['can_separate']) && $_GET['can_separate'] != "") {
                $can_separate = intval($_GET['can_separate']);
                if ($can_separate >= 0) {
                    $para['can_separate'] = $can_separate;
                }

            }

            if ($_GET['rec'] != "") {
                $rec = intval($_GET['rec']);
                if ($rec >= 0) {
                    $para['rec'] = $rec;
                }

            }

            if (intval($_GET['page']) > 0) {
                $page = intval($_GET['page']);
            } else {
                $page = 1;
            }

            if ($_GET['warning'] == "yes") {
                $stat = "warn";
            }

            $this->view->data = $model->getChannelGoods($stat, $para, $page);

            //获取页码
            if ($this->view->data['maxpage'] > 1) {
                $this->view->data['spage'] = $model->fun->spage($this->view->data['page'], $this->view->data['maxpage']);
            }

            /*搜索的商品分类品牌供应商*/
            $this->view->cate  = $model->getCategory(0, false, 1); //商品分类
            $this->view->brand = $model->getBrand(0, 1, 1); //商品品牌

            if ($this->view->brand) {
                foreach ($this->view->brand as $r) {
                    $py               = strtoupper(mb_substr($model->pinyin->get($r['name']), 0, 1, "utf-8"));
                    $brand_new[$py][] = $r;
                }
                ksort($brand_new);
                $this->view->brand = $brand_new;
            }
            $this->view->supplier = $model->getSuppliers(); //供应商

            //新增权限
            $this->view->pv['add'] = $model->checkPriv($this->_pvprefix . "_ad", false, false);
            //编辑权限
            $this->view->pv['edit'] = $model->checkPriv($this->_pvprefix . "_ed", false, false);
            //库存权限
            $this->view->pv['stock'] = $model->checkPriv($this->_pvprefix . "_st", false, false);
            //报损权限
            $this->view->pv['damaged'] = $model->checkPriv($this->_pvprefix . "_dm", false, false);
            //报损权限
            $this->view->pv['chart'] = $model->checkPriv($this->_pvprefix . "_ch", false, false);
            //删除权限
            $this->view->pv['del'] = $model->checkPriv($this->_pvprefix . "_de", false, false);
            //删除权限
            $this->view->pv['relevance'] = $model->checkPriv($this->_pvprefix . "_rele", false, false);

            //商品导出
            $this->view->pv['ex'] = $model->checkPriv($this->_pvprefix . "_ex", false, false);

            //商品导入
            $this->view->pv['im'] = $model->checkPriv($this->_pvprefix . "_im", false, false);

            //成本价可见权限
            $this->view->pv['purview'] = $model->checkPriv($this->_pvprefix . "_purview", false, false);

            //上架设置
            $this->view->pv['onsale'] = $model->checkPriv($this->_pvprefix . "_onsale", false, false);

            //规格设置
            $this->view->pv['spec'] = $model->checkPriv($this->_pvprefix . "_gsc", false, false);

            $this->display();

        }

    }

    //新增商品
    public function add()
    {
        $priv = array($this->_pvprefix . "_ad");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth     = $auth;
            $this->view->supplier = $model->getSuppliers();
            $this->view->province = $model->getprovince();
// var_dump($this->view->province);exit;
            $goods_id = intval($_GET['goods_id']);
            if ($goods_id > 0) {
                $data = $model->getSingleGoods($goods_id);
            }

            if ($data) {

                //商品图片
                if ($data['pic_docid'] > 0) {
                    $docid[] = $data['pic_docid'];
                }

                if ($data['pic2_docid'] > 0) {
                    $docid[] = $data['pic2_docid'];
                }

                if ($data['pic3_docid'] > 0) {
                    $docid[] = $data['pic3_docid'];
                }

                if ($data['pic4_docid'] > 0) {
                    $docid[] = $data['pic4_docid'];
                }

                if ($data['pic5_docid'] > 0) {
                    $docid[] = $data['pic5_docid'];
                }

                if ($data['thumb_docid'] > 0) {
                    $docid[] = $data['thumb_docid'];
                }

                if ($docid) {
                    $data['docs'] = $model->getDocs($docid);
                }

                $this->view->data = $data;

                // $this->view->cate = $model->getCategory(0, false, $data['shopid']);
                $this->view->cate = $model->getCategoryAll();
                $brand            = $model->getBrand(0, 1);
                if ($brand) {
                    foreach ($brand as $r) {
                        $py               = strtoupper(mb_substr($model->pinyin->get($r['name']), 0, 1, "utf-8"));
                        $brand_new[$py][] = $r;
                    }
                    ksort($brand_new);
                    $this->view->brand = $brand_new;
                }

            } else {

                $this->view->cate = $model->getCategoryAll();
                $brand            = $model->getBrand(0, 1);
                if ($brand) {
                    foreach ($brand as $r) {
                        $py               = strtoupper(mb_substr($model->pinyin->get($r['name']), 0, 1, "utf-8"));
                        $brand_new[$py][] = $r;
                    }
                    ksort($brand_new);
                    $this->view->brand = $brand_new;
                }

            }

            $this->display();
        }

    }

    // 商品库存走势
    public function chart()
    {
        $priv = array($this->_pvprefix . "_ed");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $goods_id = intval($_GET['goods_id']);
            if ($goods_id > 0) {
                $data = $model->getSingleGoods($goods_id);
            }

            if ($data) {

                $this->view->auth = $auth;
                $this->view->data = $data;

                if ($_GET['start_time'] != "") {
                    $start_time = strtotime($_GET['start_time'] . " 0:0:0");
                }

                if ($_GET['end_time'] != "") {
                    $end_time = strtotime($_GET['end_time'] . " 23:59:59");
                }

                $this->view->chart = $model->getChartData($data['goods_id'], $start_time, $end_time);

                $this->display();

            } else {
                RPHP_RR::nodata();
            }

        }

    }

    //编辑商品
    public function edit()
    {
        $priv = array($this->_pvprefix . "_ed");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $goods_id = intval($_GET['goods_id']);
            $this->view->province = $model->getprovince();
            if ($goods_id > 0) {
                $data = $model->getSingleGoods($goods_id);
                // print_r($data);
            }
            
            

            if ($data) {

                $this->view->express_setting = json_decode($data['express_setting'],true);


                $config             = $model->getSetting();
                $this->view->config = $config;
                $this->view->auth   = $auth;

                // $shopinfo = $model->getShopInfo();
                if ($shopinfo['gram_price'] != "") {
                    $this->view->gram_price = unserialize($shopinfo['gram_price']);
                } else {
                    $this->view->gram_price = false;
                }

                if ($data['hot_docid'] > 0) {
                    $docid[] = $data['hot_docid'];
                }

                //商品图片
                if ($data['pic_docid'] > 0) {
                    $docid[] = $data['pic_docid'];
                }

                if ($data['pic2_docid'] > 0) {
                    $docid[] = $data['pic2_docid'];
                }

                if ($data['pic3_docid'] > 0) {
                    $docid[] = $data['pic3_docid'];
                }

                if ($data['pic4_docid'] > 0) {
                    $docid[] = $data['pic4_docid'];
                }

                if ($data['pic5_docid'] > 0) {
                    $docid[] = $data['pic5_docid'];
                }

                if ($data['thumb_docid'] > 0) {
                    $docid[] = $data['thumb_docid'];
                }

                if ($docid) {
                    $data['docs'] = $model->getDocs($docid);
                }

                //print_r($data);die;
                //商品小图
                $uploadImages = array(
                    array('name' => '图片一'),
                    array('name' => '图片二'),
                    array('name' => '图片三'),
                    array('name' => '图片四'),
                );

                if ($data['small_docid'] != '') {
                    $docids = explode(",", $data['small_docid']);
                    if (count($docids) > 0) {
                        foreach ($docids as $key => $id) {
                            if ($id != "") {
                                $uploadImages[$key]['file'] = $model->getNewDocs($id);
                            }

                        }
                    }
                }
                $cates = $model->getCatePid($data['caid']);
                if($cates){
                    $data['yi_caid'] = $cates['fucaid'];
                    $this->view->ercate = $cates['data'];
                }
                $this->view->cate = $model->getCategoryAll();
                $this->view->uploadImages = $uploadImages;

                $this->view->supplier  = $model->getSuppliers();
                $this->view->relevance = $model->getRlevance();
                $this->view->data      = $data;


                $brand            = $model->getBrand(0, 1);
                if ($brand) {
                    foreach ($brand as $r) {
                        $py               = strtoupper(mb_substr($model->pinyin->get($r['name']), 0, 1, "utf-8"));
                        $brand_new[$py][] = $r;
                    }
                    ksort($brand_new);
                    $this->view->brand = $brand_new;
                }

                $this->display();

            } else {
                RPHP_RR::nodata();
            }

        }

    }

    //执行图片上传
    public function upload_do()
    {
        $data['code'] = 900;
        $priv         = array($this->_pvprefix . "_ls");
        $model        = $this->model;
        $auth         = $model->checkPriv($priv, true, false);
        if ($auth) {

            $data = $model->UploadPic($_FILES['files']);

        }

        $this->view->data = $data;

        $this->display();
    }
    //今日特卖
    public function today_special()
    {
        $priv = array($this->_pvprefix . "_cl");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;


            if ($_GET['start_time'] != "") {

                $para['start_time'] = strtotime($_GET['start_time']);

            }

            if ($_GET['end_time'] != "") {
                // echo  date("Y-m-d H:i:s",strtotime($_GET['end_time']));die;
                $para['end_time'] = strtotime($_GET['end_time']);

            }


            if (intval($_GET['page']) > 0) {
                $page = intval($_GET['page']);
            } else {
                $page = 1;
            }


            $this->view->data = $model->getTodaySpecical($para, $page);

            //获取页码
            if ($this->view->data['maxpage'] > 1) {
                $this->view->data['spage'] = $model->fun->spage($this->view->data['page'], $this->view->data['maxpage']);
            }


            //新增权限
            $this->view->pv['add'] = $model->checkPriv($this->_pvprefix . "_sad", false, false);
            //编辑权限
            $this->view->pv['edit'] = $model->checkPriv($this->_pvprefix . "_sed", false, false);

            //编辑权限
            $this->view->pv['del'] = $model->checkPriv($this->_pvprefix . "_sde", false, false);

            $this->display();
        }

    }
    //今日特卖新增
    public function special_add()
    {
        $priv  = array($this->_pvprefix . "_sad");
        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;
            $this->display();
        }

    }

    //今日特卖新增
    public function special_edit()
    {
        $priv  = array($this->_pvprefix . "_sed");
        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $id = intval($_GET['id']);
            $this->view->data = $model->getSpecialDetail($id);
            //dd($this->view->data);
            $this->view->auth = $auth;
            $this->display();
        }

    }

    //上传图片
    public function upload()
    {
        $priv  = array($this->_pvprefix . "_ls");
        $model = $this->model;
        $auth  = $model->checkPriv($priv, true, false);
        if ($auth) {
            $this->display();
        }
    }

    //AJAX
    public function ajax()
    {

        $priv         = array($this->_pvprefix . "_ls");
        $model        = $this->model;
        $auth         = $model->checkPriv($priv);
        $data['code'] = 901;
        if ($auth) {
            $data['code'] = 900;
            if ($_POST['act'] == "getattr") {

                $data = $model->getFormAttr($_POST['typeid']);

            }
            // 删除分类
            elseif ($_POST['act'] == "remove") {
                $caid = $_POST['caid'];
                if ($caid > 0) {
                    $model->deleteCategory($caid);
                }
                $data['code'] = 200;
            }
            // 删除品牌
            elseif ($_POST['act'] == "delete") {
                $brand_id = $_POST['brand_id'];
                if ($brand_id > 0) {
                    $model->deleteBrand($brand_id);
                }
                $data['code'] = 200;
            } elseif ($_POST['act'] == "ajax_rele") {

                $data = $model->getRlevances($_POST);

            } elseif ($_POST['act'] == "ajax_sales_count") {

                $data = $model->saveSalesCount($_POST);

            } elseif ($_POST['act'] == "ajax_goods_number" && $model->checkPriv($this->_pvprefix . "_st", false, false)) {
                //修改库存
                $data = $model->saveGoodsNumber($_POST, false);

            } elseif ($_POST['act'] == "ajax_is_on_sale" && $model->checkPriv($this->_pvprefix . "_onsale", false, false)) {
                //上下架
                $data = $model->saveIsOnSale($_POST);

            } elseif ($_POST['act'] == "ajax_shop_price") {
                //修改零售价
                $data = $model->saveShopPrice($_POST);

            } elseif ($_POST['act'] == "ajax_market_price") {
                //修改市场价
                $data = $model->saveMarketPrice($_POST);

            }
            // 获取商品关联信息
            elseif ($_POST['act'] == "getrelevance" && $model->checkPriv($this->_pvprefix . "_rele", false, false)) {

                $data = $model->getGoodsRelevance($_POST['goods_id']);

            }
            // 搜索关联标题
            elseif ($_POST['act'] == "searchrelevance" && $model->checkPriv($this->_pvprefix . "_rele", false, false)) {

                $data = $model->getRlevances($_POST);

            }
            // 保存关联商品
            elseif ($_POST['act'] == "saverelevance" && $model->checkPriv($this->_pvprefix . "_rele", false, false)) {

                $data = $model->saveGoodsRlevances($_POST);

            }
            elseif($_POST['act'] == "goods_search")
            {
                $data = $model->getGoodsSearch($_POST);

            }
            elseif($_POST['act'] == "goods_detail")
            {

                $data = $model->getGoodsDetail($_POST);
            }
            elseif($_POST['act'] == "special_del")
            {

                $data = $model->delSpecial();
            }
            elseif($_POST['act'] == "get_cate")
            {

                $data = $model->getCategoryAll($_REQUEST['caid']);
            }
            // 删除规格属性
            elseif ($_POST['act'] == "remove_spec" &&  $model->checkPriv($this->_pvprefix . "_scde", false, false)) {
              
                $caid = $_POST['caid'];
                if ($caid > 0) {
                    
                    $model->deleteSpec($caid);
                }
                $data['code'] = 200;
            }
            // 属性状态
            elseif ($_POST['act'] == "stock_stat" &&  $model->checkPriv($this->_pvprefix . "_gsc", false, false)) {



                    $model->saveSpecStat($_POST);

                $data['code'] = 200;
            }
            elseif ($_POST['act'] == "goods_spec_set" && $model->checkPriv($this->_pvprefix . "_gsc", false, false)) {
               
               //设置商品
                $data = $model->setGoodsSpec($_POST);

            }
            elseif ($_POST['act'] == "stock_edit" && $model->checkPriv($this->_pvprefix . "_gsc", false, false)) {
                 
                //修改规格库存及会员价
                $data = $model->setSpecStock($_POST);
            
            } // 删除规格图片
            elseif ($_POST['act'] == "del_pic" && $model->checkPriv($this->_pvprefix . "_sc", false, false)) {

                $data = $model->delSpecPic($_POST['id']);

            }


        }

        echo json_encode($data);

    }

    //保存商品
    public function savegoods()
    {
        $priv = array($this->_pvprefix . "_ls");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;
            $this->view->code = 900;

            if ($_POST['act'] == "add" && $model->checkPriv($this->_pvprefix . "_ad", false, false)) {
                //print_r($_FILES);die;
                $this->view->success = "新增商品成功";
                $this->view->link    = array(
                    array('name' => '继续新增商品', 'url' => '/channel/add'),
                    array('name' => '返回商品列表', 'url' => '/channel/channelgoods'),
                );
                $this->view->code = $model->saveGoods($_POST, $_FILES);

            } else if ($_POST['act'] == "channeladd" && $model->checkPriv($this->_pvprefix . "_ad", false, false)) {
                //print_r($_FILES);die;
                $this->view->success = "新增商品成功";
                $this->view->link    = array(
                    array('name' => '继续新增商品', 'url' => '/channel/add'),
                    array('name' => '返回商品列表', 'url' => '/channel/channelgoods'),
                );
                $this->view->code = $model->saveGoods($_POST, $_FILES);

            } elseif ($_POST['act'] == "edit" && $model->checkPriv($this->_pvprefix . "_ed", false, false)) {

                $this->view->success = "编辑商品成功";
                $this->view->link    = array(

                    array('name' => '返回来源页面', 'url' => $_POST['ref']),
                    array('name' => '返回商品列表', 'url' => '/channel/channelgoods'),
                );
                $this->view->code = $model->saveGoods($_POST, $_FILES, $_POST['goods_id']);

            } elseif ($_POST['act'] == "commission" && $model->checkPriv($this->_pvprefix . "_ed", false, false)) {

                $this->view->success = "编辑商品分润设置成功";
                $this->view->link    = array(

                    array('name' => '返回来源页面', 'url' => $_POST['ref']),
                    array('name' => '返回商品列表', 'url' => '/channel/channelgoods'),
                );
                $this->view->code = $model->saveGoodsCommission($_POST);

            } elseif ($_POST['act'] == "delete" && $model->checkPriv($this->_pvprefix . "_de", false, false)) {

                $this->view->success = "删除商品成功";
                $this->view->link    = array(
                    array('name' => '返回商品列表', 'url' => '/channel/channelgoods'),
                );
                $this->view->code = $model->deleteGoods($_POST['dataid']);

            } elseif ($_POST['act'] == "channeldelete" && $model->checkPriv($this->_pvprefix . "_de", false, false)) {

                $this->view->success = "删除商品成功";
                $this->view->link    = array(
                    array('name' => '返回商品列表', 'url' => '/channel/channelgoods'),
                );
                $this->view->code = $model->deleteGoods($_POST['dataid']);

            } elseif ($_POST['act'] == "goodscate" && $model->checkPriv($this->_pvprefix . "_cl", false, false)) {

                $this->view->success = "修改商品分类成功";
                $this->view->link    = array(
                    array('name' => '返回来源页面', 'url' => $_POST['ref']),
                    array('name' => '返回商品列表', 'url' => '/channel/channelgoods'),
                );
                $this->view->code = $model->saveGoodsCate($_POST);

            }
            //批量操作

            $this->displaydo();

        }
    }

    // 商品分润设置
    public function commission()
    {
        $priv = array($this->_pvprefix . "_ed");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $goods_id = intval($_GET['goods_id']);
            if ($goods_id > 0) {
                $data = $model->getSingleGoods($goods_id);
            }

            if ($data) {

                $this->view->auth = $auth;

                if($data['commission_setting']!="")
                {
                    $data['json'] = json_decode($data['commission_setting'],true);
                }

                $this->view->data = $data;



                $this->display();

            }

        }
    }

    //批量操作
    public function savebatch()
    {
        $priv = array($this->_pvprefix . "_ls");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;
            $code             = 900;


            if ($_POST['act'] == "delete" && $model->checkPriv($this->_pvprefix . "_de", false, false)) {
                //print_r($_POST);
                $this->view->success = "批量删除商品成功";
                $this->view->link    = array(
                    array('name' => '返回商品列表', 'url' => '/channel/channelgoods'),
                );
                $code = $model->saveBatch($_POST['dataid'], 'delete');

            } elseif ($_POST['act'] == "on_sale" && $model->checkPriv($this->_pvprefix . "_onsale", false, false)) {
                $this->view->success = "批量设置商品成功";
                $this->view->link    = array(
                    array('name' => '返回商品列表', 'url' => '/channel/channelgoods'),
                );
                $code = $model->saveBatch($_POST['dataid'], $_POST['act']);
            } elseif ($_POST['act'] != "channeledit" && $model->checkPriv($this->_pvprefix . "_ed", false, false)) {

                $this->view->success = "批量设置商品成功";
                $this->view->link    = array(
                    array('name' => '返回渠道商品', 'url' => '/channel/channelgoods'),
                );
                $code = $model->saveBatch($_POST['dataid'], $_POST['act']);

            } elseif ($_POST['act'] != "" && $model->checkPriv($this->_pvprefix . "_ed", false, false)) {

                $this->view->success = "批量设置商品成功";
                $this->view->link    = array(
                    array('name' => '返回商品列表', 'url' => '/channel/channelgoods'),
                );
                $code = $model->saveBatch($_POST['dataid'], $_POST['act']);

            }

            $this->view->code = $code;
            $this->displaydo();

        }
    }

/*商品品牌管理*/
    //品牌列表
    public function brand()
    {

        $priv = array($this->_pvprefix . "_br");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {

            $para = array();
            if ($_GET['keyword']) {
                $para['keyword'] = addslashes(stripslashes(trim($_GET['keyword'])));
            }

            if ($_GET['caid'] != "") {
                $para['caid'] = intval($_GET['caid']);
            }

            if ($_GET['stat'] != "") {
                $para['stat'] = intval($_GET['stat']);
            }

            $this->view->auth = $auth;

            $this->view->classlist = $model->getClasslist();

            //获取类型数据
            $this->view->data = $model->getBrandShow($para);

            $this->display();

        }

    }

    //新增品牌
    public function brand_add()
    {

        $priv = array($this->_pvprefix . "_br");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;
            $this->view->cate = $model->getClasslist();

            $this->display();

        }

    }

    //编辑品牌
    public function brand_edit()
    {

        $priv = array($this->_pvprefix . "_br");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;

            $brand_id         = intval($_GET['brand_id']);
            $data             = $model->getBrand($brand_id);
            $this->view->cate = $model->getClasslist();
            if ($data) {
                //商品图片
                if ($data['cover_pic'] > 0) {
                    $docid[] = $data['cover_pic'];
                }

                if ($data['brand_pic'] > 0) {
                    $docid[] = $data['brand_pic'];
                }

                if ($docid) {
                    $data['docs'] = $model->getDocs($docid);
                }

                $this->view->data = $data;
                $this->display();
            } else {
                RPHP_RR::nodata();
            }

        }

    }

    // 品牌操作
    public function brand_do()
    {

        $priv = array($this->_pvprefix . "_br");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;
            $this->view->code = 900;

            if ($_POST['act'] == "add") {

                $this->view->success = "新增品牌成功";
                $this->view->link    = array(
                    array('name' => '继续新增品牌', 'url' => '/channel/brand_add'),
                    array('name' => '返回品牌列表', 'url' => '/channel/brand'),
                );
                $this->view->code = $model->saveBrand($_POST, $_FILES);

            } elseif ($_POST['act'] == "edit") {

                $this->view->success = "编辑品牌成功";
                $this->view->link    = array(
                    array('name' => '返回品牌列表', 'url' => '/channel/brand'),
                );
                $this->view->code = $model->saveBrand($_POST, $_FILES, $_POST['brand_id']);

            }

            $this->displaydo();

        }

    }
/*----分类--------------*/
    //分类列表
    public function category()
    {

        $priv = array($this->_pvprefix . "_ca");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;

            //获取类型数据
            $this->view->data = $model->getCategory(0, false, 1);
            //print_r($this->view->data);
            //获取新增权限
            $this->view->pvadd = $model->checkPriv($this->_pvprefix . "_caad", false);
            //获取编辑权限
            $this->view->pvedit = $model->checkPriv($this->_pvprefix . "_caed", false);
            //获取奖励权限
            $this->view->pvcf = $model->checkPriv($this->_pvprefix . "_cacf", false);

            $this->display();

        }

    }

    //分类奖励配置
    public function cateaward()
    {
        $priv = array($this->_pvprefix . "_cacf");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;
             $caid = intval($_GET['caid']);
            //获取分类数据
            $this->view->data = $model->getcateAwardDetail($caid);

            $this->display();

        }

    }
    //新增分类
    public function cateadd()
    {

        $priv = array($this->_pvprefix . "_caad");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;

            //获取分类数据
            $this->view->data = $model->getCategory(0, false, 1);

            $this->display();

        }

    }

    //编辑分类
    public function cateedit()
    {

        $priv = array($this->_pvprefix . "_caed");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;

            $caid = intval($_GET['caid']);
            $cate = $model->getCategory($caid);
            //商品图片
            if ($cate['docid'] > 0) {
                $docid = $cate['docid'];
            }

            if ($docid) {
                $cate['docid'] = $model->getDocs($docid);
            }

            if ($cate['addocid'] > 0) {
                $docids = $cate['addocid'];
            }

            if ($docids) {
                $cate['addocid'] = $model->getDocs($docids);
            }

            if ($cate) {
                $this->view->cate                            = $cate;
                $this->view->stat[$this->view->cate['stat']] = ' checked';

                //获取类型数据
                $this->view->data = $model->getCategory();
                $this->display();
            } else {
                RPHP_RR::nodata();
            }

        }

    }

    //分类排序
    public function catesort()
    {

        $priv = array($this->_pvprefix . "_caed");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;
            $this->view->data = $model->getCategory(intval($_GET['caid']), true, 0);
            $this->display();

        }

    }

    //分类操作
    public function catedo()
    {

        $priv = array($this->_pvprefix . "_ca");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;
            $this->view->code = 900;

            if ($_POST['act'] == "add" && $model->checkPriv($this->_pvprefix . "_caad", false)) {

                $this->view->success = "新增分类成功";
                $this->view->link    = array(
                    array('name' => '继续新增分类', 'url' => '/channel/cateadd'),
                    array('name' => '返回分类列表', 'url' => '/channel/category'),
                );
                $this->view->code = $model->saveCategory($_POST, $_FILES);

            } elseif ($_POST['act'] == "edit" && $model->checkPriv($this->_pvprefix . "_caed", false)) {

                $this->view->success = "编辑分类成功";
                $this->view->link    = array(
                    array('name' => '返回分类列表', 'url' => '/channel/category'),
                );
                $this->view->code = $model->saveCategory($_POST, $_FILES, $_POST['caid']);

            } elseif ($_POST['act'] == "sort" && $model->checkPriv($this->_pvprefix . "_caed", false)) {

                $this->view->success = "保存分类排序成功";
                $this->view->link    = array(
                    array('name' => '返回分类列表', 'url' => '/channel/category'),
                );
                $this->view->code = $model->saveCategorySort($_POST);

            }
            elseif ($_POST['act'] == "award_edit" && $model->checkPriv($this->_pvprefix . "_cacf", false)) {

                $this->view->success = "保存分类奖励配置成功";
                $this->view->link    = array(
                    array('name' => '返回分类列表', 'url' => '/channel/category'),
                );
                $this->view->code = $model->saveCategoryAward($_POST);

            }

            $this->displaydo();

        }

    }

    //增加库存
    public function stock_number()
    {
        $priv  = array($this->_pvprefix . "_st");
        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;
            $goods_id         = intval($_GET['goods_id']);

            if ($_GET['ref'] != "") {
                $this->view->ref = Rfc::decode($_GET['ref']);
            } else {
                $this->view->ref = $_SERVER['HTTP_REFERER'];
            }

            $this->view->goods_number = $model->getGoodsNumber($goods_id);
            $this->view->goodsid      = $goods_id;

            $this->display();
        }

    }

    //商品报损
    public function stock_damaged()
    {
        $priv  = array($this->_pvprefix . "_dm");
        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;
            $goods_id         = intval($_GET['goods_id']);

            if ($_GET['ref'] != "") {
                $this->view->ref = Rfc::decode($_GET['ref']);
            } else {
                $this->view->ref = $_SERVER['HTTP_REFERER'];
            }

            $this->view->goods_number = $model->getGoodsNumber($goods_id);
            $this->view->goodsid      = $goods_id;

            $this->display();
        }

    }

    //    无属性时的商品库存
    public function goodsnumber()
    {

        $priv  = array($this->_pvprefix . "_st");
        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth    = $auth;
            $this->view->code    = 900;
            $this->view->success = "保存商品库存成功";
            $this->view->link    = array(
                array('name' => '返回库存列表', 'url' => '/channel/stock_number?goods_id=' . $_POST['goods_id'] . "&ref=" . Rfc::encode($_POST['ref'])),
                array('name' => '返回来源页面', 'url' => $_POST['ref']),
                array('name' => '返回商品列表', 'url' => '/channel/channelgoods'),
            );
            $this->view->code = $model->saveGoodsNumber($_POST);
            $this->displaydo();
        }
    }

    // 保存报损
    public function savedamaged()
    {
        $priv  = array($this->_pvprefix . "_dm");
        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth    = $auth;
            $this->view->code    = 900;
            $this->view->success = "保存报损数据成功";
            $this->view->link    = array(
                array('name' => '返回来源页面', 'url' => $_POST['ref']),
                array('name' => '返回商品列表', 'url' => '/channel/channelgoods'),
            );
            $this->view->code = $model->saveGoodsDamaged($_POST);
            $this->displaydo();
        }
    }

    //销售区域
    public function region()
    {

        $priv  = array($this->_pvprefix . "_re");
        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;
            $goodsid          = $_GET['goods_id'];
            if ($goodsid) {
                $this->view->province = $model->getprovince();
                $this->view->region   = $model->getGoodsRegion($goodsid);
                //print_r($this->view->region);die;
                $this->view->goods_id = $goodsid;

            }
            $this->display();
        }
    }

    //AJAX选择区域
    public function choice()
    {

        $priv         = array($this->_pvprefix . "_re");
        $model        = $this->model;
        $auth         = $model->checkPriv($priv, true, false);
        $data['code'] = 901;
        if ($auth) {
            $data['code'] = 900;
            $data         = $model->getposition($_POST['region_id']);

        }
        echo json_encode($data);
    }

    public function goods_region()
    {
        $priv  = array($this->_pvprefix . "_re");
        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            //print_r($_POST);die;
            $this->view->auth    = $auth;
            $this->view->code    = 900;
            $this->view->success = "保存地址成功";
            $this->view->link    = array(
                array('name' => '返回商品区域', 'url' => '/channel/region?goods_id=' . $_POST['goods_id']),
                array('name' => '返回商品列表', 'url' => '/channel/channelgoods'),
            );
            //print_r($_POST);die;
            $this->view->code = $model->saveRegion($_POST);
            $this->displaydo();
        }
    }

    //评论管理assessment
    public function assessment()
    {

        $priv = array($this->_pvprefix . "_ass");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;

            if ($_GET['keyword'] != "") {
                $keyword = addslashes(trim($_GET['keyword']));
                if ($keyword != '') {
                    $para['keyword'] = $keyword;
                }

            }

            if ($_GET['stat'] != "") {
                $stat = intval($_GET['stat']);
                if ($stat != '') {
                    $para['stat'] = $stat;
                }

            }

            if (intval($_GET['page']) > 0) {
                $page = intval($_GET['page']);
            } else {
                $page = 1;
            }

            $this->view->data = $model->getGoodsComment($para, $page);
            //获取页码
            if ($this->view->data['maxpage'] > 1) {
                $this->view->data['spage'] = $model->fun->spage($this->view->data['page'], $this->view->data['maxpage']);
            }

            $this->display();

        }

    }

    //AjaxStat审核评论状态
    public function AjaxStat()
    {
        $priv = array($this->_pvprefix . "_ass");

        $m    = $this->model;
        $auth = $m->checkPriv($priv);
        if ($auth) {
            $data = $m->saveCommentStat($_POST);
        }
        echo json_encode($data);
    }

    /*----分类--------------*/
    //品牌分类列表
    public function classlist()
    {

        $priv = array($this->_pvprefix . "_clt");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;

            //获取类型数据
            $this->view->data = $model->getClasslist();

            $this->display();

        }

    }

    //新增分类
    public function classadd()
    {
        $priv = array($this->_pvprefix . "_clt");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;

            //获取分类数据
            $this->view->data = $model->getClasslist();
            $this->display();

        }

    }

    //编辑分类
    public function classedit()
    {

        $priv = array($this->_pvprefix . "_clt");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;
            $caid             = intval($_GET['caid']);
            $cate             = $model->getClasslist($caid);

            //商品图片
            if ($cate['docid'] > 0) {
                $docid = $cate['docid'];
            }

            if ($docid) {
                $cate['docid'] = $model->getDocs($docid);
            }

            if ($cate) {
                $this->view->cate                            = $cate;
                $this->view->stat[$this->view->cate['stat']] = ' checked';
                //获取类型数据
                $this->view->data = $model->getClasslist();
                $this->display();
            } else {
                RPHP_RR::nodata();
            }

        }

    }

    //分类排序
    public function classsort()
    {

        $priv = array($this->_pvprefix . "_clt");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;
            $this->view->data = $model->getClasslist(intval($_GET['caid']), true);
            $this->display();

        }

    }

    //分类操作
    public function classdo()
    {

        $priv = array($this->_pvprefix . "_clt");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;
            $this->view->code = 900;

            if ($_POST['act'] == "add" && $model->checkPriv($this->_pvprefix . "_clt", false)) {

                $this->view->success = "新增分类成功";
                $this->view->link    = array(
                    array('name' => '继续新增分类', 'url' => '/channel/classadd'),
                    array('name' => '返回分类列表', 'url' => '/channel/classlist'),
                );
                $this->view->code = $model->saveClass($_POST, $_FILES);

            } elseif ($_POST['act'] == "edit" && $model->checkPriv($this->_pvprefix . "_clt", false)) {

                $this->view->success = "编辑分类成功";
                $this->view->link    = array(
                    array('name' => '返回分类列表', 'url' => '/channel/classlist'),
                );
                $this->view->code = $model->saveClass($_POST, $_FILES, $_POST['caid']);

            } elseif ($_POST['act'] == "sort" && $model->checkPriv($this->_pvprefix . "_claed", false)) {

                $this->view->success = "保存分类排序成功";
                $this->view->link    = array(
                    array('name' => '返回分类列表', 'url' => '/channel/classlist'),
                );
                $this->view->code = $model->saveCategorySorts($_POST);

            }

            $this->displaydo();

        }

    }

//供应商列表
    public function supplier()
    {
        $priv = array($this->_pvprefix . "_supp");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;
            if ($_GET['keyword'] != "") {
                $keyword = addslashes(trim($_GET['keyword']));
                if ($keyword != '') {
                    $para['keyword'] = $keyword;
                }

            }

            if (intval($_GET['page']) > 0) {
                $page = intval($_GET['page']);
            } else {
                $page = 1;
            }

            $this->view->data = $model->getSupplierlist($para, $page);

            //获取页码
            if ($this->view->data['maxpage'] > 1) {
                $this->view->data['spage'] = $model->fun->spage($this->view->data['page'], $this->view->data['maxpage']);
            }

            //新增权限
            $this->view->pv['add'] = $model->checkPriv($this->_pvprefix . "_st", false);
            //修改权限
            $this->view->pv['edit'] = $model->checkPriv($this->_pvprefix . "_st", false);
            //删除权限
            $this->view->pv['del'] = $model->checkPriv($this->_pvprefix . "_st", false);
            $this->display();
        }
    }

    //supplier_add新增供应商
    public function supplier_add()
    {
        $priv = array($this->_pvprefix . "_supp");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;

            $this->view->province = $model->getRegion(1);
            $this->display();
        }
    }

    //supplier_edit新增供应商
    public function supplier_edit()
    {
        $priv = array($this->_pvprefix . "_supp");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $id = intval($_GET['id']);
            if ($id > 0) {
                $data = $model->getSingleSupplier($id);
            }

            if ($data) {
                $this->view->auth = $auth;

                $this->view->province = $model->getRegion(1);
                if ($data['province'] > 0) {
                    $this->view->city = $model->getRegion($data['province']);
                }

                if ($data['city'] > 0) {
                    $this->view->county = $model->getRegion($data['city']);
                }

                $this->view->data = $data;
                $this->display();

            } else {
                RPHP_RR::nodata();
            }

        }
    }
    //saveSupplier保存供应商信息
    public function saveSupplier()
    {
        $priv = array($this->_pvprefix . "_supp");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;
            $this->view->code = 900;

            if ($_POST['act'] == "add") {
                $this->view->success = "新增供应商信息成功";
                $this->view->link    = array(
                    array('name' => '继续新增供应商信息', 'url' => '/channel/supplier_add'),
                    array('name' => '返回供应商信息列表', 'url' => '/channel/supplier'),
                );
                $this->view->code = $model->saveSupplier($_POST,$_FILES);
            } elseif ($_POST['act'] == "edit") {
                $this->view->success = "编辑供应商信息成功";
                $this->view->link    = array(
                    array('name' => '返回供应商信息列表', 'url' => '/channel/supplier'),
                );
                $this->view->code = $model->saveSupplier($_POST,$_FILES, $_POST['id']);

            } elseif ($_POST['act'] == "delete") {
                $this->view->success = "删除供应商信息成功";
                $this->view->link    = array(
                    array('name' => '返回供应商信息列表', 'url' => '/channel/supplier'),
                );
                $this->view->code = $model->del_supplier($_POST['dataid'], 'delete');

            } elseif ($_POST['act'] == "delAll") {
                $this->view->success = "删除供应商信息成功";
                $this->view->link    = array(
                    array('name' => '返回供应商信息列表', 'url' => '/channel/supplier'),
                );
                $this->view->code = $model->del_supplier($_POST['dataid'], 'delAll');

            }
            $this->displaydo();
        }
    }
    //今日特卖保存
    public function savespecial()
    {
        $priv = array($this->_pvprefix . "_si");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;
            $this->view->code = 900;

            if ($_POST['act'] == "add" &&  $model->checkPriv($this->_pvprefix . "_sad", false, false)) {
                $this->view->success = "新增今日特卖成功";
                $this->view->link    = array(
                    array('name' => '继续新增今日特卖', 'url' => '/channel/special_add'),
                    array('name' => '返回今日特卖列表', 'url' => '/channel/today_special'),
                );
                $this->view->code = $model->saveSpecial($_POST);
            } elseif ($_POST['act'] == "edit") {
                $this->view->success = "编辑今日特卖成功";
                $this->view->link    = array(
                    array('name' => '返回今日特卖列表', 'url' => '/channel/today_special'),
                );
                $this->view->code = $model->saveSpecial();

            } elseif ($_POST['act'] == "delete") {
                $this->view->success = "删除供应商信息成功";
                $this->view->link    = array(
                    array('name' => '返回供应商信息列表', 'url' => '/channel/supplier'),
                );
                $this->view->code = $model->del_supplier($_POST['dataid'], 'delete');

            } elseif ($_POST['act'] == "delAll") {
                $this->view->success = "删除供应商信息成功";
                $this->view->link    = array(
                    array('name' => '返回供应商信息列表', 'url' => '/channel/supplier'),
                );
                $this->view->code = $model->del_supplier($_POST['dataid'], 'delAll');

            }
            $this->displaydo();
        }
    }

    //AJAX操作
    public function supplierAjax()
    {

        $priv = array($this->_pvprefix . "_supp");

        $model        = $this->model;
        $auth         = $model->checkPriv($priv);
        $data['code'] = 900;
        if ($auth) {
            if ($_POST['act'] == 'getregion') {
                $rs           = $model->getRegion(intval($_POST['parent_id']));
                $data['code'] = 200;
                $data['data'] = $rs;
            }
        }
        echo json_encode($data);
    }

    //验证手机号码是否存在
    public function Ajaxsearchphone()
    {
        $m    = $this->model;
        $code = 800;
        $priv = array($this->_pvprefix . "_st");
        $auth = $m->checkPriv($priv);
        if ($auth) {
            //var_dump($_POST);die;
            $code = $m->searchPhone($_POST);
        }
        echo $code;
    }

    public function saveAjaxSupplier()
    {
        $priv = array($this->_pvprefix . "_supp");
        $m    = $this->model;
        $auth = $m->checkPriv($priv);
        $arr  = array("statu" => 'y', "info" => '');
        if ($auth) {
            $data = $m->saveSupplier($_POST);
            if ($data) {
                $arr = array("statu" => 'y', "info" => $m->get_supp());
            } else {
                $arr = array("statu" => 'n');
            }
        }
        echo json_encode($arr);
    }

    //渠道商品导出页面
    public function export()
    {
        $priv = array($this->_pvprefix . "_st");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;

            $this->view->cate     = $model->getCategory(0, false, 1); //商品分类
            $this->view->brand    = $model->getBrand(0, 1); //商品品牌
            $this->view->supplier = $model->getSuppliers(); //供应商

            $this->display();
        }
    }

    //渠道商品导入页面
    public function import()
    {
        $priv = array($this->_pvprefix . "_st");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;
            $this->display();
        }
    }

    //批量导出渠道商品
    public function exportBatch()
    {
        $priv = array($this->_pvprefix . "_ex");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;

            if ($_GET['caid'] != "") {
                $caid = intval($_GET['caid']);
                if ($caid > 0) {
                    $para['caid'] = $caid;
                }

            }
            if ($_GET['brand_id'] != "") {
                $brand_id = intval($_GET['brand_id']);
                if ($brand_id > 0) {
                    $para['brand_id'] = $brand_id;
                }

            }

            if ($_GET['goods_name'] != "") {

                $para['goods_name'] = trim($_GET['goods_name']);

            }
            // if ($_GET['supplier_id'] != "") {
            //     $supplier_id = intval($_GET['supplier_id']);
            //     if ($supplier_id > 0) {
            //         $para['supplier_id'] = $supplier_id;
            //     }

            // }

            if (isset($_GET['is_on_sale']) && $_GET['is_on_sale'] != "") {

                $para['is_on_sale'] = intval($_GET['is_on_sale']);

            }

            $data = $model->getDerive($para);
            RPHP::loadClass("PHPExcel", "extend/PHPExcel/Classes");
            $excel       = new PHPExcel();
            $letter      = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I');
            $tableheader = array('商品ID', '商品名称', '分类', '品牌', '零售价格', '市场价格', '进货价格', '库存', '上架');
            $excel_H     = 2;

            $excel->getActiveSheet()->getStyle('E')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
            $excel->getActiveSheet()->getStyle('F')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
            $excel->getActiveSheet()->getStyle('G')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
            $excel->getActiveSheet()->getStyle('H')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
            $excel->getActiveSheet()->getStyle('I')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);

            $excel->getActiveSheet()->getColumnDimension("A")->setWidth(15);
            $excel->getActiveSheet()->getColumnDimension("B")->setWidth(30);
            $excel->getActiveSheet()->getColumnDimension("C")->setWidth(12);
            $excel->getActiveSheet()->getColumnDimension("D")->setWidth(20);
            $excel->getActiveSheet()->getColumnDimension("E")->setWidth(12);
            $excel->getActiveSheet()->getColumnDimension("F")->setWidth(12);
            $excel->getActiveSheet()->getColumnDimension("G")->setWidth(15);
            $excel->getActiveSheet()->getColumnDimension("H")->setWidth(15);
            $excel->getActiveSheet()->getColumnDimension("I")->setWidth(15);
            for ($i = 0; $i < count($tableheader); $i++) {

                $excel->getActiveSheet()->setCellValue($letter[$i] . "1", $tableheader[$i]);
            }
            if ($data) {
                foreach ($data as $k => $v) {
                    $line = $excel_H + $k;
                    $excel->getActiveSheet()->setCellValue('A' . $line, $v['goods_id']);
                    $excel->getActiveSheet()->setCellValue('B' . $line, $v['goods_name']);
                    $excel->getActiveSheet()->setCellValue('C' . $line, $v['caid']);
                    $excel->getActiveSheet()->setCellValue('D' . $line, $v['brand_id']);
                    $excel->getActiveSheet()->setCellValue('E' . $line, $v['shop_price']);
                    $excel->getActiveSheet()->setCellValue('F' . $line, $v['market_price']);
                    $excel->getActiveSheet()->setCellValue('G' . $line, $v['purchase_price']);
                    $excel->getActiveSheet()->setCellValue('H' . $line, $v['goods_number']);
                    $excel->getActiveSheet()->setCellValue('I' . $line, $v['is_on_sale']);

                }
            }
            //创建Excel输入对象
            $write = new PHPExcel_Writer_Excel5($excel);
            header("Pragma: public");
            header("Expires: 0");
            header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
            header("Content-Type:application/vnd.ms-execl");
            header('Content-Disposition:attachment;filename="商品列表.xls"');
            header("Content-Transfer-Encoding:binary");
            $write->save('php://output');

        }
    }

//渠道商品导入
    public function importBatch()
    {

        $priv = array($this->_pvprefix . "_im");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;
            $code             = 900;

            if ($_FILES['excelFile']['size'] > 0 && $_FILES['excelFile']['tmp_name'] != "") {
                $fi        = new finfo(FILEINFO_MIME_TYPE);
                $mime_type = $fi->file($_FILES['excelFile']['tmp_name']);
                $mime      = array(
                    2003 => array("application/vnd.ms-office", "application/msword", "application/vnd.ms-excel"),
                    2007 => array("application/zip"),
                );

                $format = explode(".", $file['name']);

                if ($format[count($format) - 1] == "xlsx") {
                    $ver = 2007;
                } elseif (in_array($mime_type, $mime[2003])) {
                    $ver = 2003;
                } elseif (in_array($mime_type, $mime[2007])) {
                    $ver = 2007;
                } else {
                    $ver = 2003;
                }

                RPHP::loadClass("PHPExcel", "extend/PHPExcel/Classes");
                RPHP::loadClass("PHPExcel_IOFactory", "extend/PHPExcel/Classes");
                RPHP::loadClass("PHPExcel_Reader_Excel5", "extend/PHPExcel/Classes");

                if ($ver == 2007) {
                    $objReader = PHPExcel_IOFactory::createReader('Excel2007');
                } else {
                    $objReader = PHPExcel_IOFactory::createReader('Excel5');
                }

                $objPHPExcel = $objReader->load($_FILES['excelFile']['tmp_name']);

                $sheet         = $objPHPExcel->getSheet(0);
                $objWorksheet  = $objPHPExcel->getActiveSheet();
                $highestRow    = $objWorksheet->getHighestRow(); //取得总行数
                $highestColumn = $objWorksheet->getHighestColumn(); //取得总列数

                $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn); //总列数
                $headtitle          = array();

                if ($highestRow >= 2) {
                    // 组合数据
                    for ($row = 2; $row <= $highestRow; $row++) {
                        for ($col = 0; $col < $highestColumnIndex; $col++) {
                            $tmp              = $objWorksheet->getCellByColumnAndRow($col, $row)->getValue();
                            $data[$row][$col] = trim($tmp);
                        }
                    }
                }

                if ($data) {
                    $code = $model->saveImport($data);
                } else {
                    $code = 404;
                }
            }

            @unlink($_FILES['excelFile']['tmp_name']);

            $this->view->success = "导入渠道商品成功";
            $this->view->link    = array(
                array('name' => '返回继续导入', 'url' => '/channel/import'),
                array('name' => '返回渠道商品', 'url' => '/channel/channelgoods'),
            );

            $this->view->code = $code;
            $this->displaydo();

        }
    }
    //批量修改商品分类
    public function savegoodscate()
    {
        $priv = array($this->_pvprefix . "_cl");

        $model     = $this->model;
        $auth      = $model->checkPriv($priv);
        $goods_ids = empty($_GET['goods_ids']) ? '' : trim($_GET['goods_ids']);
        //获取分类数据

        if (!empty($goods_ids)) {
            $this->view->cate      = $model->getCategory(0, false, 1); //商品分类
            $this->view->auth      = $auth;
            $this->view->goods_ids = $goods_ids;
            $this->display();
        }

    }
}
